<template>
    <div>
        <el-header style="text-align: right; font-size: 15px">
            <span>
                欢迎使用学籍管理系统-新生注册
            </span>
        </el-header>
        <el-form  style="margin-top:25px" :model="ruleForm" :rules="rules" ref="ruleForm" label-width="10%"  class="demo-ruleForm">
            <el-form-item label="姓名" prop="s_name">
                <el-input v-model="ruleForm.s_name"></el-input>
            </el-form-item>
            <el-form-item label="性别" prop="s_sex">
                <el-select v-model="ruleForm.s_sex" placeholder="请选择">
                    <el-option label="男" value="男"></el-option>
                    <el-option label="女" value="女"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="年龄" prop="s_age">
                <el-input v-model="ruleForm.s_age"></el-input>
            </el-form-item>
            <el-form-item label="民族" prop="s_nation">
                <el-input v-model="ruleForm.s_nation"></el-input>
            </el-form-item>
            <el-form-item label="政治面貌" prop="s_political">
                <el-select v-model="ruleForm.s_political" placeholder="请选择">
                    <el-option label="群众" value="群众"></el-option>
                    <el-option label="少先队员" value="少先队员"></el-option>
                    <el-option label="共青团员" value="共青团员"></el-option>
                    <el-option label="共产党员" value="共产党员"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="年级" prop="s_grade">
                <el-input v-model="ruleForm.s_grade"></el-input>
            </el-form-item>

            <el-form-item label="专业" prop="m_id">
                <el-select v-model="ruleForm.m_id" placeholder="请选择">
                    <el-option label="软件工程" value="201"></el-option>
                    <el-option label="网络工程" value="202"></el-option>
                    <el-option label="计算机科学与技术" value="203"></el-option>
                </el-select>
            </el-form-item>

            <el-form-item label="班级" prop="s_class">
                <el-input v-model="ruleForm.s_class"></el-input>
            </el-form-item>



            <el-form-item label="地区" prop="s_area">
                <el-input v-model="ruleForm.s_area"></el-input>
            </el-form-item>

            <el-form-item label="休复转退标记" prop="s_return">
                <el-select v-model="ruleForm.s_return" placeholder="请选择">
                    <el-option label="在读" value="在读"></el-option>
                    <el-option label="复学" value="复学"></el-option>
                    <el-option label="转学" value="转学"></el-option>
                    <el-option label="退学" value="退学"></el-option>
                    <el-option label="休学" value="休学"></el-option>
                </el-select>
            </el-form-item>

            <el-form-item label="奖惩概述" prop="s_records">
                <el-input type="textarea" v-model="ruleForm.s_records"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="submitForm('ruleForm')">立即注册</el-button>
                <el-button type="primary" @click="resetForm('ruleForm')">重置</el-button>
            </el-form-item>
        </el-form>
    </div>

</template>
<script>
    export default {
        data() {
            return {
                ruleForm: {
                    s_name: '',
                    s_sex: '',
                    s_grade: '',
                    s_class: '',
                    s_area: '',
                    s_age: '',
                    s_political: '',
                    s_nation: '',
                    s_return: '',
                    s_records: '',
                    m_id: ''
                },
                rules: {
                    s_name: [
                        { required: true, message: '请输入姓名', trigger: 'blur' },
                        { min: 1, max: 15, message: '长度在 1 到 15 个字符', trigger: 'blur' }
                    ],
                    s_sex: [
                        { required: true, message: '请选择性别', trigger: 'change' }
                    ],
                    s_grade: [
                        { required: true, message: '请填写年级', trigger: 'blur' }
                    ],
                    s_class: [
                        { required: true, message: '请填写班级', trigger: 'blur' }
                    ],
                    m_id: [
                        { required: true, message: '请选择专业', trigger: 'change' }
                    ],
                    s_area: [
                        { required: true, message: '请填写学生来自地区', trigger: 'blur' }
                    ],
                    s_age: [
                        { required: true, message: '请填写年龄', trigger: 'blur' },
                    ],
                    s_political: [
                        { required: true, message: '请填写学生政治面貌', trigger: 'blur' }
                    ],
                    s_nation: [
                        { required: true, message: '请填写学生民族', trigger: 'blur' }
                    ],
                    s_return: [
                        { required: true, message: '请选择', trigger: 'change' }
                    ],
                    s_records: [
                        { required: true, message: '请填写奖惩记录(没有请填“无”)', trigger: 'blur' }
                    ]
                }
            };
        },
        methods: {
            submitForm(formName) {
                const _this = this
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        axios.post('http://localhost:8181/student/save',this.ruleForm).then(function (resp) {
                            if(resp.data =='success'){
                                _this.$message({
                                    message: '注册成功！',
                                    type: 'success'
                                });
                                _this.$refs[formName].resetFields();
                            }

                        })
                    } else {
                        return false;
                    }
                });
            },
            resetForm(formName) {
                this.$refs[formName].resetFields();
            }
        }
    }
</script>